/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package verification;

import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JPanel;

/**
 *
 * @author NATHAN
 */
public class SsnFieldVerifier extends AbstractValidator {

  private int length;

  public SsnFieldVerifier(JPanel parent, JComponent c, String message, int length) {
    super(parent, c, message);
    this.length = length;
  }

  @Override
  protected boolean validationCriteria(JComponent c) {
    String ssn = ((JFormattedTextField) c).getText().replaceAll("[^0-9]", "");

    //length check
    if (ssn.length() != length) {
      setMessage("SSN has to be 9 digits.");
      ((JFormattedTextField) c).selectAll();
      return false;
    }
    return true;
  }
}
